<template>
  <div class="cant-buy-dialog">
    <el-dialog
      class="cantBuyDialog"
      :visible="isShowCantBuyDialog"
      top="20vh"
      center
      :before-close="closeCantBuyDialog"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div class="dialog-title">
        <img @click="closeCantBuyDialog" src="@/assets/images/pc_black/auth/close.png" />
      </div>

      <div class="dialog-content">
        <div class="dialog-content-title">{{ titleCpt() }}</div>
        <div class="dialog-content-ewm">
          <img v-for="(item, index) in ewmUrls" :key="index" :src="item.image" />
        </div>
        <div class="dialog-content-bottom">{{ descCpt() }}</div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { isIOS } from "@/utils";

export default {
  name: "CantBuyDialog",
  props: {
    isShowCantBuyDialog: {
      type: Boolean,
      default: false
    },
    ewmUrls: {
      type: Array,
      required: true
    },
    productData: {
      type: Object,
      required: true
    },
    // -1已结束 0已售罄 1预售
    status: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 关闭弹窗
    closeCantBuyDialog() {
      this.$emit("handleCloseCantBuyDialog");
    },
    // 转换发布时间
    getTime() {
      let startDate;
      if (isIOS()) {
        startDate = new Date(this.productData.pre_start_time.replace(/-/g, "/"));
      } else {
        startDate = new Date(this.productData.pre_start_time);
      }
      let now = new Date().getTime();
      let start = startDate.getTime();
      let timestamp = start - now;
      let date = parseInt(timestamp / 1000 / 60 / 60 / 24);
      let hours = parseInt((timestamp / 1000 / 60 / 60) % 24);
      let minute = parseInt((timestamp / 1000 / 60) % 60);
      if (date === 0 && hours === 0 && minute === 0) minute += 1;
      return date + "天" + hours + "小时" + minute + "分";
    },
    // 标题显示
    titleCpt() {
      let result;
      switch (this.status) {
        case -1:
          result = this.productData.goods_name + "藏品发售已结束";
          break;
        case 0:
          result = this.productData.goods_name + "藏品已售罄";
          break;
        case 1:
          result = "还有" + this.getTime() + "发售";
          break;
        default:
          result = "正在加载";
          break;
      }
      return result;
    },
    descCpt() {
      let result;
      switch (this.status) {
        case -1:
          result = "长按扫码关注，获取官方最新动态";
          break;
        case 0:
          result = "长按扫码关注，获取官方最新动态";
          break;
        case 1:
          result = "即刻扫码加入社群，获得发售提醒";
          break;
        default:
          result = "正在加载";
          break;
      }
      return result;
    }
  }
};
</script>

<style lang="less" scoped>
.cant-buy-dialog {
  width: 100%;
  height: 100%;

  // cantBuy dialog
  .cantBuyDialog {
    /deep/.el-dialog {
      width: 500px;
      height: 400px;
      background: #1e2020;
      border-radius: 10px;

      .el-dialog__header {
        display: none;
      }
      .el-dialog__body {
        margin: 0;
        padding: 0;

        .dialog-title {
          display: flex;
          justify-content: flex-end;
          width: 100%;
          padding: 30px 30px 0 0;

          img {
            width: 16px;
            height: 16px;
            cursor: pointer;
          }
        }
        .dialog-content {
          position: relative;
          width: 100%;
          padding-top: 25px;

          .dialog-content-title {
            font-size: 18px;
            font-family: PingFangSC-Semibold, PingFang SC;
            font-weight: 600;
            color: #ffffff;
            line-height: 18px;
            text-align: center;
          }

          .dialog-content-ewm {
            display: flex;
            justify-content: center;
            margin-top: 30px;
            font-size: 0;

            img {
              width: 150px;
              height: 150px;
              margin-left: 20px;
            }
            img:first-child {
              margin: 0;
            }
          }

          .dialog-content-bottom {
            font-size: 16px;
            font-family: PingFangSC-Semibold, PingFang SC;
            font-weight: 600;
            color: #999999;
            line-height: 16px;
            text-align: center;
            margin-top: 40px;
          }
        }

        // 双击不选中
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        -khtml-user-select: none;
        user-select: none;
      }
    }
  }

  /deep/.el-dialog__wrapper {
    background: rgba(0, 0, 0, 0.8);
  }
}

@media screen and (max-width: 768px) {
  .cant-buy-dialog {
    .cantBuyDialog {
      /deep/.el-dialog {
        width: 90%;
        height: 650px;

        .el-dialog__body {
          .dialog-title {
            padding: 30px 30px 0 0;

            img {
              width: 32px;
              height: 32px;
            }
          }
          .dialog-content {
            padding-top: 50px;

            .dialog-content-title {
              font-size: 36px;
              line-height: 36px;
            }

            .dialog-content-ewm {
              margin-top: 60px;

              img {
                width: 250px;
                height: 250px;
                margin-left: 40px;
              }
            }

            .dialog-content-bottom {
              font-size: 30px;
              line-height: 30px;
              margin-top: 70px;
            }
          }
        }
      }
    }
  }
}
</style>
